home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr48 / 386p_200.zip / JOY.ASM < prev    next >
Assembly Source File  |  1995-01-14  |  5KB  |  196 lines

  1. ; 386POWER example program #1.
  2.  
  3.         .386p
  4. code32 segment para public use32
  5.        assume cs:code32,ds:code32
  6.  
  7. include 386power.inc
  8. include 386video.inc
  9. include 386keyb.inc
  10. include 386mouse.inc
  11. include 386joy.inc
  12. include 386file.inc
  13. include pix.inc
  14. include pcx.inc
  15. include picture.inc
  16. include chario.inc
  17. include pattern.inc
  18. include chtil.inc
  19.  
  20. public  _Main
  21.         align byte
  22. Picture dd 0        
  23. Sprite  dd 0
  24. Pattern dd 0
  25. MouPat  dd 0
  26. MouN    dd 0
  27. PatBase dd 0
  28.  
  29. Pcxname db  'JOY.PCX',0
  30. Fntname db  'CHARSET.CBF',0
  31.         
  32. epcx    db 'No JOY.PCX file found!',CR,LF,'$'
  33. echar   db 'No GREEN.CBF font file found!',CR,LF,'$'
  34.  
  35. inputs  db 12 dup(0)
  36.         
  37. titlepcx  db 'JOYSTICK TEST (press a key)',0
  38.  
  39. caliber   db 'JOYSTICK CALIBRATED, try moving it',0
  40. esca      db '-> press ESC  to exit from here <-',0
  41.  
  42. _Main:  sti ; enable interrupts and get running
  43.  
  44.         ; first of all initialize display driver
  45.         mov _DispX,320
  46.         mov _DispY,200
  47.         mov _ScrX,RXWIDTH+XBORDER
  48.         mov _ScrY,VYHEIGHT+(YBORDER*2)+SCOREBOARD+1
  49.         call _SetXVDMode
  50.         ; position the "view" window into the display buffer
  51.         mov eax,XBORDER
  52.         mov edx,YBORDER
  53.         call _DisplayStart
  54.         
  55.         ; load title screen 
  56.         ; n.b. in ther upper left there is the "pointer" bitmap
  57.         ;      the program will use to show the mouse position
  58.         mov esi,offset Pcxname 
  59.         call _PcxLoad          
  60.         mov _386Return, offset epcx
  61.         cmp _PcxDecoded,0
  62.         je Bye
  63.         call _PageFlip0 ; show image
  64.         
  65.         ; load character font file
  66.         mov _386Return, offset echar
  67.         mov esi,offset Fntname ; load font into low memory
  68.         call _LoadCharSet          ;
  69.         jc Bye
  70.         ; get the mouse cursor image from JOY.PCX
  71.         mov esi,_ScrBase
  72.         mov eax,XBORDER
  73.         mov edx,YBORDER
  74.         mov ecx,4  ; 16 pixels = 4 nudget
  75.         mov ebx,13 ; pixels
  76.         mov edi,_LoMemBase
  77.         mov Picture,edi
  78.         call _GetPic
  79.         ; compile it to TRLE bitmap format
  80.         mov  Sprite,edi
  81.         mov  esi,Picture
  82.         call _Pic2Spt
  83.         mov _LoMemBase,edi ; set new _LoMemBase
  84.         
  85.         mov edi,_LoMemBase
  86.         
  87.         
  88.         ; show program name
  89.         mov eax,0
  90.         call _ScrClr
  91.         mov edi,_ScrBase
  92.         mov eax,XBORDER+2
  93.         mov edx,2+RYHEIGHT+YBORDER
  94.         mov ebx, offset titlepcx
  95.         call _PutString
  96.         call _PageFlip0
  97.         
  98.         mov esi,MAIN_JOYSTICK
  99.         call _StickOK
  100.         jnc jinit_ok
  101.         call _InitStick
  102. jinit_ok:
  103.         ; then install the "raw keyboard" driver
  104.         call _KeybInst
  105.         mov edi,_ScrBase
  106.         call _PageFlip0
  107.         xor eax,eax
  108.         xor edx,edx
  109. tiloop: 
  110.         pushad
  111.         mov ecx,4  ; 16 dots wide = 4 dwords
  112.         mov ebx,13 ; 13 dots tall
  113.         call _TouchBlock
  114.         add eax,XBORDER
  115.         add edx,YBORDER
  116.         mov esi,Sprite
  117.         mov ebx,0
  118.         call _PutSpt
  119.         ; now write mouse position
  120.         mov eax,XBORDER
  121.         mov edx,RYHEIGHT+YBORDER-20
  122.         mov ebx,offset caliber
  123.         call _PutString
  124.         add edx,8
  125.         mov ebx,offset esca
  126.         call _PutString
  127.         sub eax,XBORDER
  128.         sub edx,YBORDER+8
  129.         mov ecx,80
  130.         mov ebx,16
  131.         call _TouchBlock
  132.         popad
  133.         call _PageFlip1
  134.         pushad
  135.         mov ecx,4  ; 16 dots wide = 4 dwords
  136.         mov ebx,13 ; 13 dots tall
  137.         call _TouchBlock
  138.         add eax,XBORDER
  139.         add edx,YBORDER
  140.         mov ecx,4
  141.         mov ebx,14
  142.         mov esi,0
  143.         call _Block   ; erase pointer
  144.         popad
  145. ; change position
  146.  
  147.         push eax
  148.         push edx
  149.         mov esi,MAIN_JOYSTICK
  150.         call _ReadStick
  151.         mov ebx,eax
  152.         pop edx
  153.         pop eax
  154.         
  155.         ; check if it's a correct position
  156.         cmp edx,0
  157.         je nup
  158.         test bl,J_UP
  159.         jz nup
  160.         dec edx
  161. nup:        
  162.         cmp edx,(200-16)
  163.         jae ndown
  164.         test bl,J_DOWN
  165.         jz ndown
  166.         inc edx
  167. ndown:        
  168.         cmp eax,0
  169.         je nleft
  170.         test bl,J_LEFT
  171.         jz nleft
  172.         dec eax
  173. nleft:        
  174.         cmp eax,(320-16)
  175.         jae nright
  176.         test bl,J_RIGHT
  177.         jz nright
  178.         inc eax
  179. nright:        
  180.         push eax
  181.         call _ScanKeyb
  182.         cmp byte ptr [eax+_ESC],KPRESSED
  183.         pop eax
  184.         jne tiloop
  185.         call _RestoreTextMode
  186.         mov _386Return,offset ESCed
  187. Bye:        
  188.         jmp _Exit
  189.  
  190.  
  191. ESCed db 'You pressed ESC to correctly terminate',CR,LF,'$'
  192.         
  193. code32  ends
  194.         end
  195.  
  196.